package com.zsd.android.dblib.db;

import com.zsd.android.dblib.bean.User;

import java.util.List;

public class UserDao extends BaseDao<User> {

    @Override
    public long insert(User entity) {
        List<User> users = query(new User());
        User where = null;
        for (User user : users) {
            where = new User();
            where.setId(user.getId());
            user.setStatus(0);
            update(user, where);
        }
        entity.setStatus(1);
        return super.insert(entity);
    }

    public User getCurrentUser() {
        User where = new User();
        where.setStatus(1);
        List<User> users = query(where);
        if (users.size() > 0) {
            return users.get(0);
        }
        return null;
    }
}
